package com.richest.api.controller.cn.merchant.merchant;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.richest.api.service.IFullReductionCommodityService;
import com.richest.bean.FullReductionCommodityBean;
import com.richest.util.CallResults;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * API接口 企业参与满减商品信息管理接口
 * 
 * @author 杨博
 * @version com.richest.api 2.0
 */
@RestController
@RequestMapping("/FullReductionCommodityManagerController")
@Api(value = "企业参与满减商品信息管理接口")
@EnableAutoConfiguration
public class ApiFullReductionCommodityManageController {

	@Autowired
	private IFullReductionCommodityService service;

	/**
	 * 添加企业参与满减商品信息接口
	 * 
	 * @author 杨博
	 * @email wsbc12345@163.com
	 * @param bean
	 * @return
	 */
	@RequestMapping(value = "fullReductionCommodityAdd", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "添加企业参与满减商品信息", value = "添加企业参与满减商品信息", httpMethod = "POST")
	@ApiImplicitParam(name = "bean", value = "企业参与满减商品信息Bean", required = true, paramType = "body", dataType = "FullReductionCommodityBean")
	public CallResults fullReductionCommodityAdd(@RequestBody FullReductionCommodityBean bean) {
		int result = service.fullReductionCommodityAdd(bean);
		if (result == 1) {
			return CallResults.ok();
		} else {
			return CallResults.error().put("message", "受影响的行数：" + result);
		}
	}

	/**
	 * 修改企业参与满减商品信息
	 * 
	 * @author 杨博
	 * @email wsbc12345@163.com
	 * @param bean
	 * @return
	 */
	@RequestMapping(value = "fullReductionCommodityUpdate", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "修改企业参与满减商品信息", value = "修改企业参与满减商品信息", httpMethod = "POST")
	@ApiImplicitParam(name = "bean", value = "企业参与满减商品信息Bean", required = true, paramType = "body", dataType = "FullReductionCommodityBean")
	public CallResults fullReductionCommodityUpdate(@RequestBody FullReductionCommodityBean bean) {
		int result = service.fullReductionCommodityUpdate(bean);
		if (result == 1) {
			return CallResults.ok();
		} else {
			return CallResults.error().put("message", "受影响的行数：" + result);
		}
	}

	/**
	 * 删除企业参与满减商品信息
	 * 
	 * @author 杨博 
	 * @email wsbc12345@163.com
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "fullReductionCommodityDelete", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "删除企业参与满减商品信息", value = "删除企业参与满减商品信息", httpMethod = "POST")
	@ApiImplicitParam(name = "id", value = "企业参与满减商品信息id", required = true, paramType = "body", dataType = "java.lang.Long")
	public CallResults fullReductionCommodityDelete(@RequestParam Long id) {
		int result = service.fullReductionCommodityDelete(id);
		if (result == 1) {
			return CallResults.ok();
		} else {
			return CallResults.error().put("message", "受影响的行数：" + result);
		}
	}

	/**
	 * 通过id获取参与满减商品信息实体
	 * 
	 * @author 杨博 
	 * @email wsbc12345@163.com
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "fullReductionCommoditySelectOne", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "获取单一的企业参与满减商品信息", value = "获取单一的企业参与满减商品信息", httpMethod = "GET")
	@ApiImplicitParam(name = "id", value = "企业参与满减商品信息id", required = true, paramType = "query", dataType = "java.lang.Long")
	public CallResults fullReductionCommoditySelectOne(@RequestParam Long id) {
		FullReductionCommodityBean bean = service.fullReductionCommoditySelectOne(id);
		return CallResults.ok().put("SelectOne", bean);
	}

	/**
	 * 获取企业参与满减商品信息集合 通过参数设置分页大小，并取回指定分页
	 * 
	 * @author 杨博
	 * @email wsbc12345@163.com
	 * @param column
	 *            要匹配的字段名称
	 * @param value
	 *            要匹配的字段值
	 * @param page
	 *            页数
	 * @param size
	 *            页码
	 * @return 参与满减商品信息集合
	 */
	@RequestMapping(value = "fullReductionCommoditySelectMap", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "获取企业参与满减商品信息集合，参数设置匹配字段，参数设置匹配值，参数设置分页大小，参数指定获取指定分页", value = "获取企业参与满减商品信息集合，参数设置分页大小，参数指定获取指定分页", httpMethod = "GET")
	@ApiImplicitParams({ @ApiImplicitParam(name = "column", value = "参与匹配的字段名称", paramType = "query"),
			@ApiImplicitParam(name = "value", value = "参与匹配的字段值", paramType = "query"),
			@ApiImplicitParam(name = "page", value = "页数", paramType = "query", dataType = "Int"),
			@ApiImplicitParam(name = "size", value = "页码", paramType = "query", dataType = "Int") })
	public CallResults fullReductionCommoditySelectMap(@RequestParam String column, @RequestParam String value,
			@RequestParam Integer page, @RequestParam Integer size) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("column", column);
		map.put("value", value);
		map.put("beginNumber", (page - 1) * size);
		map.put("endNumber", size);
		List<Map<String, Object>> lst = new ArrayList<>();
		lst = service.fullReductionCommoditySelectMap(map);
		return CallResults.ok().put("SelectMap", lst);
	}

}
